package cn.dogger.easyboot.system.service.impl;


import cn.dogger.easyboot.common.exception.RollBackException;
import cn.dogger.easyboot.system.domain.bo.SysRoleDeptBO;
import cn.dogger.easyboot.system.domain.dto.SysRoleDeptDTO;
import cn.dogger.easyboot.system.domain.entity.SysRoleDept;
import cn.dogger.easyboot.system.domain.vo.SysRoleDeptDetail;
import cn.dogger.easyboot.system.domain.vo.SysRoleDeptVO;
import cn.dogger.easyboot.system.mapper.SysRoleDeptMapper;
import cn.dogger.easyboot.system.service.SysRoleDeptService;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
* 角色和部门关联表
* @author dogger
* 2022-04-16
*/
@Service
public class SysRoleDeptServiceImpl  extends ServiceImpl<SysRoleDeptMapper, SysRoleDept> implements SysRoleDeptService {

         private final SysRoleDeptMapper mapper;

         public SysRoleDeptServiceImpl(SysRoleDeptMapper mapper) {
            this.mapper = mapper;
         }
         
    @Override
    public List<SysRoleDeptVO> page(SysRoleDeptDTO dto) {
        return mapper.list(dto);
    }


    @Override
    @Transactional(rollbackFor = RollBackException.class)
    public void add(SysRoleDeptBO bo) {
        SysRoleDept entity = BeanUtil.copyProperties(bo, SysRoleDept.class);
        mapper.insert(entity);
    }

    @Override
    @Transactional(rollbackFor = RollBackException.class)
    public void edit(SysRoleDeptBO bo) {
        SysRoleDept entity = BeanUtil.copyProperties(bo, SysRoleDept.class);
        mapper.updateById(entity);
    }

    @Override
    public SysRoleDeptDetail detailById(String id) {
       SysRoleDept entity =  mapper.selectById(id);
        return BeanUtil.toBean(entity,SysRoleDeptDetail.class);
    }

    @Override
    public void removeByIds(String[] ids) {
        List<String> list = Arrays.asList(ids);
        mapper.deleteBatchIds(list);
    }
}